class Todo {
  int? id;
  final String title;
  final String description;
  final bool isCompleted;
  final DateTime createdAt;

  Todo({
    this.id,
    required this.title,
    this.description = "",
    this.isCompleted = false,
    required this.createdAt,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'title': title,
      'description': description,
      'isCompleted': isCompleted ? 1 : 0,
      'createdAt': createdAt.millisecondsSinceEpoch,
    };
  }
  factory Todo.fromMap(Map<String,dynamic> map){
    return Todo(
        id: map['id'],
        title:map['title'],
        description:map['description'],
        isCompleted:map['isCompleted']==1,
        createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
    );
  }
}